<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">

    <meta name="twitter:site" content="@metroui">
    <meta name="twitter:creator" content="@pimenov_sergey">
    <meta name="twitter:card" content="summary">
    <meta name="twitter:title" content="Metro 4 Components Library">
    <meta name="twitter:description" content="Metro 4 is an open source toolkit for developing with HTML, CSS, and JS. Quickly prototype your ideas or build your entire app with responsive grid system, extensive prebuilt components, and powerful plugins  .">
    <meta name="twitter:image" content="https://metroui.org.ua/images/m4-logo-social.png">

    <meta property="og:url" content="https://metroui.org.ua/v4/index.html">
    <meta property="og:title" content="Metro 4 Components Library">
    <meta property="og:description" content="Metro 4 is an open source toolkit for developing with HTML, CSS, and JS. Quickly prototype your ideas or build your entire app with responsive grid system, extensive prebuilt components, and powerful plugins  .">
    <meta property="og:type" content="website">
    <meta property="og:image" content="https://metroui.org.ua/images/m4-logo-social.png">
    <meta property="og:image:secure_url" content="https://metroui.org.ua/images/m4-logo-social.png">
    <meta property="og:image:type" content="image/png">
    <meta property="og:image:width" content="968">
    <meta property="og:image:height" content="504">

    <meta name="author" content="Sergey Pimenov">
    <meta name="description" content="The most popular HTML, CSS, and JS library in Metro style.">
    <meta name="keywords" content="HTML, CSS, JS, Metro, CSS3, Javascript, HTML5, UI, Library, Web, Development, Framework">

    <link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
    <link rel="icon" href="favicon.ico" type="image/x-icon">

    <link href="metro/css/metro-all.css?ver=@@b-version" rel="stylesheet">
    <link href="highlight/styles/github.css" rel="stylesheet">
    <link href="docsearch/docsearch.min.css" rel="stylesheet">
    <link href="css/site.css" rel="stylesheet">

    <title>M4Q Attributes - Metro 4 :: Popular HTML, CSS and JS library</title>

    <style>
        .demo-box {
            width: 100px;
            height: 100px;
            margin: 10px auto;
        }
    </style>
</head>
<body class="m4-cloak">

<header data-role="html-container" data-insert-mode="replace" data-html-source="header.html"></header>

<div data-role="html-container" data-insert-mode="replace" data-html-source="sidebar-menu.html"></div>

<div class="container-fluid docs-content">

    <div class="row flex-xl-nowrap">

            <div class="d-none d-block-xl cell-xl-2 order-2 border-left bd-light toc-wrapper">
                <h5>Table of contents</h5>
                <hr/>
                <ul class="toc-nav">
                    <li class="toc-entry"><a href="#">About</a></li>
                </ul>

            </div>

            <main class="cell-xl-10 order-1 pr-1-sx pl-1-sx pr-5-md pl-5-md">
                <div class="place-right d-none d-block-lg" style="width: 200px;">
                    <img src="images/logo.png" class="w-100" alt="">
                </div>

                <h1>M4Q Attributes</h1>
                <p class="text-leader">
                    Use special attributes functions to work with element attributes.
                </p>

                <!-- ads-html -->

                <h3>About</h3>
                <p>
                    You can work with element attributes with special attributes functions:
                        <code>attr()</code>,
                        <code>removeAttr()</code>,
                        <code>toggleAttr()</code>,
                        <code>id()</code>,
                        <code>prop()</code>,
                        <code>meta()</code>,
                        <code>metaBy()</code>,
                        <code>doctype()</code>,
                        <code>html()</code>.
                        <code>document()</code>.
                        <code>window()</code>.
                        <code>head()</code>.
                </p>

                <h3>attr()</h3>
                <p>
                    You can manipulate element attributes with it.
                </p>

                <p class="text-bold">Get all attributes</p>
                <pre><code>
                    $.each($(selector).attr(), function(key, val){
                        console.log("Attribute " + key + " has value " + val);
                    });
                </code></pre>

                <p class="text-bold">Get attribute by name</p>
                <pre><code>
                    var id = $(selector).attr("id");
                    console.log("Element ID: " + id);
                </code></pre>

                <p class="text-bold">Set attribute by name</p>
                <pre><code>
                    $(selector).attr("id", "element_id");
                </code></pre>

                <p class="text-bold">Set attributes</p>
                <pre><code>
                    $(selector).attr({
                        "id": "element_id",
                        "class": "me-class",
                        "style": "display: none"
                    });
                </code></pre>

                <h3>removeAttr()</h3>
                <p>
                    Remove attributes.
                </p>

                <p class="text-bold">Remove all attributes</p>
                <pre><code>
                    $(selector).removeAttr();
                </code></pre>

                <p class="text-bold">Remove attribute by name</p>
                <pre><code>
                    $(selector).removeAttr("id");
                </code></pre>

                <p class="text-bold">Remove attribute by names</p>
                <pre><code>
                    $(selector).removeAttr("id, class, style");
                </code></pre>

                <h3>toggleAttr()</h3>
                <p>
                    Remove or set attribute by name.
                </p>

                <p class="text-bold">Remove attribute</p>
                <pre><code>
                    $(selector).toggleAttr("id");
                </code></pre>

                <p class="text-bold">Set attribute value</p>
                <pre><code>
                    $(selector).toggleAttr("id", "element_id");
                </code></pre>

                <h3>id()</h3>
                <p>
                    Get or set element ID for first element in set.
                </p>
                <pre><code>
                    $(selector).id("id", "elementID"); // set
                    console.log( "Element ID: " + $(selector).id("id") ); // get
                </code></pre>

                <h3>prop()</h3>
                <p>
                    Get or set element property for all elements in set. You can set <code>hidden</code>, <code>checked</code> and <code>disabled</code> properties.
                    Get return property value for first element in set.
                </p>
                <pre><code>
                    $(selector).prop("checked"); // get
                    $(selector).prop("checked", true); // set
                </code></pre>

                <h3>doctype()</h3>
                <p>
                    Get page <code>DOCTYPE</code> element.
                </p>
                <pre><code>
                    $.doctype(); // get page DOCTYPE
                </code></pre>

                <h3>html()</h3>
                <p>
                    Get page <code>html</code> element.
                </p>
                <pre><code>
                    $.html(); // get page DOCTYPE
                </code></pre>

                <h3>document()</h3>
                <p>
                    Get document object.
                </p>
                <pre><code>
                    $.document(); // this eq to $("document")
                </code></pre>

                <h3>window()</h3>
                <p>
                    Get window object.
                </p>
                <pre><code>
                    $.window(); // this eq to $(window)
                </code></pre>

                <h3>head()</h3>
                <p>
                    Get document head object.
                </p>
                <pre><code>
                    $.head(); // this eq to $("head")
                </code></pre>

                <h3>meta()</h3>
                <p>
                    Get <code>meta</code> attributes.
                </p>
                <pre><code>
                    $.meta(); // get all document meta attributes
                    $.meta("viewport"); // get meta with name viewport
                </code></pre>

                <h3>metaBy(what)</h3>
                <p>
                    Get <code>meta</code> by attribute name.
                </p>
                <pre><code>
                    $.meta("property", "og:url"); // get meta with attribute name property and specified value
                </code></pre>

                <h3>charset()</h3>
                <p>
                    Get or set <code>meta charset</code>.
                </p>
                <pre><code>
                    $.charset(); // get meta charset
                    $.charset("UTF-8"); // set and get meta charset
                </code></pre>


            </main>
        </div>

    </div>

    <script src="docsearch/docsearch.min.js"></script>


    <script src="metro/js/metro.js?ver=@@b-version"></script>
    <script src="highlight/highlight.pack.js"></script>
    <script src="js/clipboard.min.js"></script>
    <script src="js/site.js"></script>
    <!-- ads-script -->
    <!-- ga-script -->
    <!-- hit-ua -->
</body>
</html>